package com.gyy.flutter.plugin.flutter_plugin_print_a300.newprint.base;

import android.content.Context;
import android.graphics.Bitmap;


import com.gyy.flutter.plugin.flutter_plugin_print_a300.common.StringUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import HPRTAndroidSDKA300.HPRTPrinterHelper;

/**
 * 打印的基类：打印时 调用改类
 */
public class BasePointPrint {

    /**
     * 打印抽象工厂（根据deviceName，生成对应设备的 打印类）
     */
    protected IPrint iPrint;


    public BasePointPrint(String deviceName) {
        this.iPrint = IPrintFactory.createPrint(deviceName);
    }

    public void commonPrint(HashMap<String, String> printMap,  Context baseContext) {

        //获取打印状态
        iPrint.getPrintState();
        iPrint.pageStart(60, 40);// 胶贴的大小格式
        try {

            //品牌
//            iPrint.printPcText(10, 0,printMap.get(PrintKey.BRAND), 7,
//                    0, true,100, 50, false, "4");

//            iPrint.printPcText(8, 1,"A", 7,
//                    0, true,100, 50, false, "3");
//            iPrint.printPcText(8 + 5, 3,"7-3-", 7,
//                    0, true,100, 50, false, "2");
//            iPrint.printPcText(8 + 8 + 7, 1,"6817", 7,
//                    0, true,100, 50, false, "3");
            String moveStr = printMap.get(PrintKey.PREFIX_MOVE);
            int move = 0;
            if (!StringUtil.isEmpty(moveStr)) {
                move = Integer.parseInt(moveStr);
            }

            iPrint.printPcText(8, 1,printMap.get(PrintKey.BRAND), 7,
                    0, true,100, 50, false, "3");
            iPrint.printPcText(8 + 4 + move, 3,printMap.get(PrintKey.PREFIX), 7,
                    0, true,100, 50, false, "2");
            iPrint.printPcText(8 + 8 + 11, 1,printMap.get(PrintKey.SUFFIX), 7,
                    0, true,100, 50, false, "3");

            //店名
            iPrint.printPcText(10, 11,printMap.get(PrintKey.SHOP), 7,
                    0, false,100, 50, false, "");
            //包装
            iPrint.printPcText(10, 15,printMap.get(PrintKey.PACKAGE), 7,
                    0, false,70, 30, false, "");
            //二维码
            String s = printMap.get(PrintKey.QRCODE);
            iPrint.printPcQRCode("360","2", "1", "5", s);
//            if (s != null && s.length() >= 60) {
//                iPrint.printPcQRCode("330","0", "1", "5", s);
//            } else {
//                iPrint.printPcQRCode("330","0", "1", "6", s);
//            }
            //条码
            iPrint.printPcBarCode(8, 26, printMap.get(PrintKey.BARCODE), 55, 10, 3, 0);
            iPrint.printPcText(22, 35,printMap.get(PrintKey.BARCODE), 7,
                    0, false,100, 50, false, "2");

            //1, 0度打印
//            iPrint.printPcText(7, 0,"良品", 7,
//                    0, true,100, 50, false, "4");
//            //店名
//            iPrint.printPcText(7, 14,"布莱特玩具专营店", 7,
//                    0, false,100, 50, false, "");
//            //包装
//            iPrint.printPcText(7, 18,"盒装-A01黑粉蓝银", 7,
//                    0, false,100, 50, false, "");
//            //二维码
//            iPrint.printPcQRCode("320","0", "1", "7", "1689769076,260028697616,YT3735281596253");
//            //条码
//            iPrint.printPcBarCode(5, 23, "POP12345678901234", 55, 10, 3, 0);
//            iPrint.printPcText(20, 32,"POP12345678901234", 7,
//                    0, false,100, 50, false, "2");


            //2，90度打印
//            iPrint.printPcText(52, 0,printMap.get(PrintKey.BRAND), 7,
//                    90, true,100, 50, false, "4");
//            //店名
//            iPrint.printPcText(39, 0,printMap.get(PrintKey.SHOP), 7,
//                    90, false,100, 50, false, "");
//            //包装
//            iPrint.printPcText(35, 0,printMap.get(PrintKey.PACKAGE), 7,
//                    90, false,100, 50, false, "");
//            //二维码
//            iPrint.printPcQRCode("255","255", "1", "7", printMap.get(PrintKey.QRCODE));
//
//            iPrint.printPcBarCode(0, 0, printMap.get(PrintKey.BARCODE), 55, 10, 3, 270);
//            iPrint.printPcText(21, 20,printMap.get(PrintKey.BARCODE), 7,
//                    90, false,100, 50, false, "2");

        } catch (Exception e) {

        }

        iPrint.pageFree();
    }


}
